from Products.CMFCore.utils import getToolByName
from my315ok.flowrate.config import docid
from my315ok.flowrate import total
from my315ok.flowrate.interfaces.flowrate import Iflowrate 

def addaccess(site,event):
#    import pdb
#    pdb.set_trace()
#    obj = site
#    pc = getToolByName(site, 'portal_catalog')
    global total
    pl = getToolByName(site, 'portal_url')
    url = pl.getPhysicalPath()
    
    target = '/' + url[1] + docid
#    query = {'id':'total',
#             'path':path}
#    brain = pc(query)
#    if len(brain) > 0:
#        doc = brain[0].getObject
#    else:
#        return
#    
    try:
        doc = pl.unrestrictedTraverse(target)
    except:
        return
    if Iflowrate.providedBy(doc):
        
        total = int(doc.getTotal())
        total = total + 1
       
    else:
        pass
    return
    
    
   
